<?php

#namespace Giocondo;

# entry -- A widget which allows the user to input a small amount of text.
class Entry extends Widget {
	protected $options = array(
		'maxLength'  => -1,
		'onChanged'  => '',
		'value'      => '',
		'widthChars' => -1
	);

	public function __construct($options = array()) {
		parent::__construct($options);
	}

	public function onChanged() {
		return $this->onEvent('onChanged', array('v' => $this->options['value']));
	}

	public function setValue($value) {
		$this->options['value'] = $value;
		return FALSE;
	}

	public function display($options=array()) {
		# Attach hidden event to update value.
		parent::display(array('onChanged' => sprintf('e(%u,1);', $this->id)));

		XHtml::element('input', NULL, array(
			'id'        => $this->id,
			'type'      => 'text',
			'value'     => $this->options['value'],
			'size'      => $this->options['widthChars'],
			'maxlength' => $this->options['maxLength']
		));
	}
}

# End of file
# vim: set ts=2 sw=2 noet:
?>
